package com.xiaoshuidi.cloud.module.member.controller.admin.programarticle;

import com.xiaoshuidi.cloud.framework.common.pojo.CommonResult;
import com.xiaoshuidi.cloud.framework.common.pojo.PageResult;
import com.xiaoshuidi.cloud.module.member.controller.admin.programarticle.vo.MemberArticleCreateVO;
import com.xiaoshuidi.cloud.module.member.controller.admin.programarticle.vo.ProgramCreateVO;
import com.xiaoshuidi.cloud.module.member.controller.admin.programarticle.vo.ProgramPageVO;
import com.xiaoshuidi.cloud.module.member.controller.admin.programarticle.vo.ProgramRespVO;
import com.xiaoshuidi.cloud.module.member.enums.ApiConstants;
import com.xiaoshuidi.cloud.module.member.service.programarticle.MemberProgramInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

import static com.xiaoshuidi.cloud.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 栏目")
@RestController
@RequestMapping(ApiConstants.NAME+"/program")
@Validated
public class MemberProgramInfoController {
    @Resource
    private MemberProgramInfoService memberProgramInfoService;
    @PostMapping("/create")
    @Operation(summary = "新增信息公告或常见问题栏目")
    public CommonResult<Boolean> create(@Valid @RequestBody ProgramCreateVO vo) {
        return success(memberProgramInfoService.create(vo));
    }

    @PostMapping("/page")
    @Operation(summary = "分页查询栏目列表")
    public CommonResult<PageResult<ProgramRespVO>> getPage(@Valid @RequestBody ProgramPageVO pageVo) {
        return success(memberProgramInfoService.getPage(pageVo));
    }

    @PostMapping("/info/page")
    @Operation(summary = "分页查询信息公告列表")
    @PreAuthorize("@ss.hasAnyPermissions('member:program:list')")
    public CommonResult<PageResult<ProgramRespVO>> getInfoPage(@Valid @RequestBody ProgramPageVO pageVo) {
        return success(memberProgramInfoService.getPage(pageVo));
    }

    @PostMapping("/edit")
    @Operation(summary = "修改信息公告或常见问题栏目")
    public CommonResult<Boolean> edit(@Valid @RequestBody ProgramCreateVO vo) {
        return success(memberProgramInfoService.edit(vo));
    }
}
